package cn.YstAdmin.service.impl;

import cn.YstAdmin.dao.YstAdminDao;
import cn.YstAdmin.service.YstAdminService;
import cn.util.aliyun.AliyunOSSClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("ystAdminService")
public class YstAdminServiceImpl implements YstAdminService {

    @Autowired
    AliyunOSSClientUtil aliyunOSSClientUtil;

    @Autowired
    YstAdminDao ystAdminDao;

    /**
     * 图片上传
     * @param params
     * @param files
     * @return
     */
    public String UploadOSS(Map<String, Object> params,MultipartFile[] files) {
        if(params.get("path").equals("product")){
            params.put("path","public/product/images/");
        }else if(params.get("path").equals("logo")){
            params.put("path","public/images/");
        }

        return aliyunOSSClientUtil.UploadOSS(null, files[0],params.get("path").toString(),1).get("imageurl").toString();
    }

    /**
     * 获取基本信息
     * @param params
     * @return
     */
    public Map<String, Object> getYstInfo(Map<String, Object> params) {
        return ystAdminDao.getYstInfo(params);
    }

    /**
     * 获取阿里云OSS
     * @param params
     * @return
     */
    public Map<String, Object> getYstALiOSS(Map<String, Object> params) {
        return ystAdminDao.getYstALiOSS(params);
    }

    /**
     * 获取Redis信息
     * @param params
     * @return
     */
    public Map<String, Object> getYstRedis(Map<String, Object> params) {
        return ystAdminDao.getYstRedis(params);
    }

    /**
     * 修改系统设置
     * @param params
     * @return
     */
    public int updateadminSystemBase(Map<String, Object> params) {
        //Redis缓存启用/不启用      form 不勾选 是不会传key的  所以是不启用
        if(!params.containsKey("REDISXS")){
            params.put("REDISXS",0);
        }
        return   ystAdminDao.updateadminSystemBase(params);
    }

    /**
     * Shiro过滤链 加载
     * @param params
     * @return
     */
    public List<Map<String, Object>> getYstShiro(Map<String, Object> params) {
        return null;
    }

    @Override
    public List<Map<String, Object>> getadminRole(Map<String, Object> params) {
        return ystAdminDao.getadminRole(params);
    }
}
